package lambdasinaction.chap1;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import static java.util.Comparator.comparing;

/**
 * <strong>实现功能:</strong>
 * <p></p>
 *
 * @author 秦有宝
 * @version 1.0.0  2019/2/14 14:17
 */
public class OldDemo {
    public static void main(String ... args){
        List<FilteringApples.Apple> inventory = Arrays.asList(new FilteringApples.Apple(80,"green"),
                new FilteringApples.Apple(155, "green"),
                new FilteringApples.Apple(120, "red"));

        //Java 8 以前
        Collections.sort(inventory, new Comparator<FilteringApples.Apple>() {
            public int compare(FilteringApples.Apple a1, FilteringApples.Apple a2){
                return a1.getWeight().compareTo(a2.getWeight());
            }
        });

        //本书中第一段Java 8的代码！
        inventory.sort(comparing(FilteringApples.Apple::getWeight));



    }
}
